package cn.study.eurekaclient.controller;

import cn.study.eurekaclient.entity.Animal;
import cn.study.eurekaclient.entity.User;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class FeignTestController {

    @GetMapping("/findById")
    public User findById(Integer id){
        System.out.println("通过id查找");
        User user = new User();
        user.setBirthday(new Date());
        user.setId(id);
        user.setName("张三");
        return  user;
    }

    @PostMapping("/test1")
    public Map<String,Object> test1(@RequestBody Map<String,Object> ret){
        return ret;

    }

    @GetMapping("/findByIdAndName")
    public User findByIdAndName(Integer id,String name){
        System.out.println("通过id查找");
        User user = new User();
        user.setBirthday(new Date());
        user.setId(id);
        user.setName(name);
        return  user;
    }

    @GetMapping("/findByCondition")
    public User findByCondition(Map<String,Object> condition){
        System.out.println("通过Map查找");
        User user = new User();
        user.setBirthday(new Date());
        user.setId(1);
        user.setName(condition.get("name").toString());
        return  user;
    }

    @GetMapping("/findByEntity")
    public User findByEntity(User user){
        System.out.println("通过Entity条件查找");
        return  user;
    }

    @PostMapping("/addUser")
    public User addUser(@RequestBody User user){
        System.out.println("添加用户");
        System.out.println(user.getId());
        return user;
    }

    @PostMapping("/addUserMap")
    public Map<String,Object> addUserMap(@RequestBody Map<String,Object> user){
        System.out.println("添加用户");
        return  user;
    }

    @PostMapping("/test")
    public Map<String,Object> test(@RequestBody Map<String,Object> user,String key){
        user.put(key, key);
        return user;
    }




}
